#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// PandoraFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion
using System.IO;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace PandoraEditor
{
    public static class PdrAssetMenu
    {
        [MenuItem("Assets/UI工具/压缩图集RGBA", false, 101)]
        static void CompressTrueAtlas()
        {
            PdrExecuteHelper.ExecuteAssetOperate(AtlasMaker.MakeUIUnCompressAtlas, SelectionMode.Assets);
        }
        [MenuItem("Assets/UI工具/压缩图集RGBA", true)]
        static bool CompressTrueAtlasCheck()
        {
            return CheckAtlas();
        }
        [MenuItem("Assets/UI工具/压缩单图RGB", false, 102)]
        static void CompressSingleAtlasNoAlpha()
        {
            PdrExecuteHelper.ExecuteAssetOperate(AtlasMaker.MakeUICompressSingleAtlasNoAlpha, SelectionMode.Assets);
        }
        [MenuItem("Assets/UI工具/压缩单图RGB", true)]
        static bool CompressSingleAtlasNoAlphaCheck()
        {
            return CheckAtlas();
        }
        [MenuItem("Assets/UI工具/创建Blur材质", false, 103)]
        static void CreateBlurMaterial()
        {
            PdrExecuteHelper.ExecuteAssetOperate(AtlasMaker.MakeBlurMaterial, SelectionMode.Assets);
        }
        [MenuItem("Assets/UI工具/创建Blur材质", true)]
        static bool CreateBlurMaterialCheck()
        {
            return CheckAtlas();
        }
        private static bool CheckAtlas()
        {
            Object[] items = Selection.GetFiltered(typeof(Object), SelectionMode.Assets);
            string headPath = UserSetting.UISetting.path_atlas + "/";
            return items.Length > 0 && items.Select(AssetDatabase.GetAssetPath).All(path => path.ToLower().StartsWith(headPath) && Directory.Exists(path));
        }
    }
}